<?php

use yii\log\FileTarget;

$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php')
);

return [
    'id'        => 'api',
    'basePath'  => dirname(__DIR__),
    'bootstrap' => [
        'log',
    ],

    'controllerNamespace' => 'api\controllers',
    'components'          => [

        'authManager'      => [
            'class'           => 'yii\rbac\DbManager',
            'itemTable'       => 'vip_item',
            'assignmentTable' => 'vip_assignment',
            'itemChildTable'  => 'vip_item_child',
            'ruleTable'       => 'vip_rule',
        ],
//
//        'Image'      => [
//            'class' => 'api\modules\image\Image',
//        ],
        'user'             => [
            'class'         => yii\web\User::className(),
            'identityClass' => common\models\User::className()
        ],
        'log'              => [//此项具体详细配置，请访问http://wiki.feehi.com/index.php?title=Yii2_log
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets'    => [
                [
                    'class'   => yii\log\FileTarget::className(),//当触发levels配置的错误级别时，保存到日志文件
                    'levels'  => ['error', 'warning'],
                    'logFile' => '@runtime/logs/' . date('Y/m/d') . '.log',
                ],
                [
                    'class'   => yii\log\FileTarget::className(),//当触发levels配置的错误级别时，保存到日志文件
                    'levels'  => ['error', 'warning'],
                    'logFile' => '@runtime/logs/debug.log',
                ],
                [
                    'class'   => yii\log\EmailTarget::className(),//当触发levels配置的错误级别时，发送到此些邮箱（请改成自己的邮箱）
                    'levels'  => ['error', 'warning'],
                    /*'categories' => [//默认匹配所有分类。启用此项后，仅匹配数组中的分类信息会触发邮件提醒（白名单）
                        'yii\db\*',
                        'yii\web\HttpException:*',
                    ],*/
                    'except'  => [//以下配置，除了匹配数组中的分类信息都会触发邮件提醒（黑名单）
                        'yii\web\HttpException:404',
                        'yii\web\HttpException:403',
                        'yii\debug\Module::checkAccess',
                    ],
                    'message' => [
                        'to'      => ['mars167@icloud.com', 'sunjinhui167@163.com'],
                        'subject' => '错误日志',
                    ],
                ],
            ],
        ],
        'cache'            => [
            'class'     => yii\caching\DummyCache::className(),
            'keyPrefix' => 'api',       // 唯一键前缀
        ],
        'urlManager'       => [
            'enablePrettyUrl'     => true,
            'enableStrictParsing' => true,
            'showScriptName'      => false,
            'rules'               => [
                ''                                    => 'site/index',
                'POST login'                          => 'user/login',
                'POST login0'                         => 'user/login0',
                'GET test'                            => 'article/test',
                'PUT user'                            => 'user/update-self',
                'GET user'                            => 'user/view-self',
                'POST no-water-image'                 => 'image/avatar',
                'GET colors'                          => 'good/colors',
                'GET personal-certification'  => 'user-certification/personal',
                'GET business-certification'  => 'user-certification/business',
                'POST personal-certification' => 'user-certification/personal-update',
                'POST business-certification' => 'user-certification/business-update',
                'POST order'                  => 'order/order',
                'GET notify'                  => 'order/notify',
                'POST notify'                 => 'order/notify',
                'GET services'                => 'good/services',
//                'GET  order/<id:\w+>'                 => 'order/view',
                'GET rule'                    => 'rule/add',
                'GET banners/<type:\w+>'      => 'banner/banner',
                'GET ads/<name:\w+>'          => 'banner/ads',
                'GET settings'                => 'banner/settings',
                'GET job-types/job'           => 'job-type/job',
                'GET job-types/mission'               => 'job-type/mission',
                'GET search-options'                  => 'job-type/default',
                'GET sms'                             => 'sms/test',
                'POST order-test'                     => 'order/order-test',
                'GET  notify-test/<out_trade_no:\w+>' => 'order/notify-test',
                'POST buy'                            => 'good/buy',
                [
                    'class'      => yii\rest\UrlRule::className(),
                    'controller' => ['user', 'article'],
//                    'extraPatterns' => [
//                        'GET search' => 'search',
//                    ],
                ],
                [
                    'class'      => \yii\rest\UrlRule::className(),
                    'controller' => ['user-certification'],

//                    'except'     => [ 'option', 'delete', 'index'],
                ],
                [
                    'class'      => \yii\rest\UrlRule::className(),
                    'controller' => ['image'],
//                    'extraPatterns' => [
//                        'GET search' => 'search',
//                    ],
                    'except'     => ['option', 'delete'],
                ],
                [
                    'class'         => \yii\rest\UrlRule::className(),
                    'controller'    => ['part-time', 'mission'],
                    'extraPatterns' => [
                        'GET signed'           => 'sign-up-job',
                        'GET posts'            => 'post',
                        'GET posts/{id}/users' => 'post-user',
                        'GET top-list'         => 'list',
                    ],
                    'except'        => ['option', 'delete'],
                ],
                [
                    'class'      => \yii\rest\UrlRule::className(),
                    'controller' => ['trash', 'comment', 'order'],

                ],
                [
                    'class'         => \yii\rest\UrlRule::className(),
                    'controller'    => ['job-record', 'complaints'],
                    'extraPatterns' => [
                        'DELETE' => 'delete',
                    ],
                ],


            ],
        ],
        'request'          => [
            'parsers'              => [
                'application/json' => 'yii\web\JsonParser',
                'text/json'        => 'yii\web\JsonParser',
            ],
            'enableCsrfValidation' => false,
            'cookieValidationKey'  => 'JKjklasjdfIJOu1123',
        ],
        'on beforeRequest' => [feehi\components\Feehi::className(), 'configInit'],
        'response'         => [
            'format'    => yii\web\Response::FORMAT_JSON,
            'as format' => api\behaviors\ResponseFormatBehavior::className()
        ],
    ],
    'params'              => $params,
];
